package com.aspose.cells;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;

class zajh {
   private static Comparator a = new zqf();
   private static final com.aspose.cells.b.c.a.za b = new com.aspose.cells.b.c.a.za(new String[]{"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"});

   static String a(String var0) {
      String var1 = com.aspose.cells.a.c.zt.b(var0);
      String var2 = var0.substring(0, 0 + (var0.length() - var1.length()));
      String var3 = var2 + "_rels/" + var1 + ".rels";
      return var3;
   }

   static ArrayList a(zcfw var0) throws Exception {
      d(var0);
      if (var0.n()) {
         return null;
      } else {
         ArrayList var1 = new ArrayList();
         var0.d();

         while(var0.r() != 4) {
            var0.j();
            if (var0.r() != 1) {
               var0.a();
            } else if ("Relationship".equals(var0.p())) {
               zqe var2 = c(var0);
               com.aspose.cells.b.a.a.ze.a(var1, (Object)var2);
            } else {
               var0.a();
            }
         }

         return var1;
      }
   }

   static HashMap b(zcfw var0) throws Exception {
      d(var0);
      if (var0.n()) {
         return null;
      } else {
         HashMap var1 = new HashMap();
         var0.d();

         while(var0.r() != 4) {
            var0.j();
            if (var0.r() != 1) {
               var0.a();
            } else if ("Relationship".equals(var0.p())) {
               zqe var2 = c(var0);
               var1.put(var2.c, var2);
            } else {
               var0.a();
            }
         }

         return var1;
      }
   }

   static HashMap a(zcfw var0, zoz var1, Workbook var2, com.aspose.cells.a.f.zi var3) throws Exception {
      HashMap var4 = b(var0);
      Iterator var5 = var4.keySet().iterator();

      while(var5.hasNext()) {
         String var6 = (String)var5.next();
         zqe var7 = (zqe)var4.get(var6);
         switch(b.a(var7.d)) {
         case 0:
            try {
               int var8 = -1;
               if (!"NULL".equals(var7.e)) {
                  String var9 = zase.aD(var7.e);
                  Object var10 = null;
                  if (var1 != null) {
                     var10 = var1.f.get(var9);
                  }

                  if (var10 == null) {
                     com.aspose.cells.a.f.zh var11 = var3.a(var9);
                     if (var11 != null && var11.a() > 0L) {
                        com.aspose.cells.b.a.d.zm var12 = var3.a(var11);
                        byte[] var13 = new byte[(int)var11.a()];
                        var12.a(var13, 0, var13.length);
                        var12.a();
                        if (com.aspose.cells.a.d.zbn.a(var13) == 0) {
                           var7.i = var13;
                        } else {
                           var8 = var2.getWorksheets().Q().b().a(var13);
                        }
                     }

                     if (var1 != null) {
                        var1.f.put(var9, var8);
                     }
                  } else {
                     var8 = (Integer)var10;
                  }
               }

               var7.g = var8;
               if (var8 != -1) {
                  var7.h = var2.getWorksheets().Q().b().a(var8);
               }

               com.aspose.cells.b.a.a.ze.a(var2.b.h, (Object)com.aspose.cells.b.a.d.zk.b(var7.e));
            } catch (Exception var15) {
               ;
            }
         }
      }

      return var4;
   }

   private static zqe c(zcfw var0) throws Exception {
      if (!var0.m()) {
         throw new CellsException(6, "Invalid Relationship element");
      } else {
         zqe var1 = new zqe();

         while(var0.l()) {
            if ("Id".equals(var0.p())) {
               var1.c = var0.s();
            } else if ("Type".equals(var0.p())) {
               var1.d = var0.s();
            } else if ("Target".equals(var0.p())) {
               var1.e = var0.s();
            } else if ("TargetMode".equals(var0.p())) {
               var1.f = var0.s();
            }
         }

         var0.k();
         var0.a();
         return var1;
      }
   }

   private static void d(zcfw var0) throws Exception {
      var0.j();
      if (var0.r() != 1 || !"Relationships".equals(var0.p())) {
         throw new CellsException(6, "Relationships root element eror");
      }
   }

   static zqe a(HashMap var0, String var1) {
      if (var0 != null && var0.size() != 0) {
         Iterator var2 = var0.values().iterator();

         zqe var3;
         do {
            if (!var2.hasNext()) {
               return null;
            }

            var3 = (zqe)var2.next();
         } while(!var3.d.equals(var1));

         return var3;
      } else {
         return null;
      }
   }

   static zqe b(HashMap var0, String var1) {
      if (var0 != null && var0.size() != 0) {
         Iterator var2 = var0.values().iterator();

         zqe var3;
         do {
            if (!var2.hasNext()) {
               return null;
            }

            var3 = (zqe)var2.next();
         } while(!com.aspose.cells.b.a.zv.b(var3.c, var1));

         return var3;
      } else {
         return null;
      }
   }

   static zqe a(ArrayList var0, String var1) {
      if (var0 != null && var0.size() != 0) {
         Iterator var2 = var0.iterator();

         zqe var3;
         do {
            if (!var2.hasNext()) {
               return null;
            }

            var3 = (zqe)var2.next();
         } while(!com.aspose.cells.b.a.zv.b(var3.c, var1));

         return var3;
      } else {
         return null;
      }
   }

   static ArrayList c(HashMap var0, String var1) {
      ArrayList var2 = new ArrayList();
      if (var0 != null && var0.size() != 0) {
         Iterator var3 = var0.values().iterator();

         while(var3.hasNext()) {
            zqe var4 = (zqe)var3.next();
            if (var4.d != null && var4.d.equals(var1)) {
               com.aspose.cells.b.a.a.ze.a(var2, (Object)var4);
            }
         }

         Collections.sort(var2, a);
         return var2;
      } else {
         return var2;
      }
   }

   static void a(HashMap var0, ArrayList var1, String var2) {
      if (var0 != null && var0.size() != 0 && var1 != null) {
         Iterator var3 = var0.values().iterator();

         while(var3.hasNext()) {
            zqe var4 = (zqe)var3.next();
            if (var4.d.equals(var2)) {
               com.aspose.cells.b.a.a.ze.a(var1, (Object)var4);
            }
         }

      }
   }
}
